$(function () {
    $.idcode.setCode();
    //侧栏的js
    //给侧栏左边添加点击事件，显示侧栏右边
    $(".asideList>.asideListLeft>a").on("click", function () {
        console.log(15487);
        $(".asideList>.asideListLeft").css("right", "200px")
        $(".asideList>.asideListRight").css("display", "block")
    })
    //隐藏右边
    $(".asideList>.asideListRight .asideListRight1").on("click", function () {
        $(".asideList>.asideListLeft").css("right", "0px")
        $(".asideList>.asideListRight").css("display", "none")
    })
    $(".asideList>.asideListRight .asideListRight2>ul>li").on("click", function () {
        $index = $(this).index();
        console.log($index);
        if ($index == 0) {
            $(".asideList>.asideListRight .asideListRight2>.ScanningLogin").css("display", "block");
            $(".asideList>.asideListRight .asideListRight2>.MemberLogin").css("display", "none");
        } else if ($index == 2) {
            $(".asideList>.asideListRight .asideListRight2>.ScanningLogin").css("display", "none");
            $(".asideList>.asideListRight .asideListRight2>.MemberLogin").css("display", "block");
        }
    })


    //登录

    //自定义规则
    //value 输入的内容
    // element 输入框
    // $.validator.addMethod("isCheckeUname", (value, element, param) => {
    //     var reg = /^(?=.*?[A-Za-z]+)(?=.*?[0-9]+)(?=.*?[A-Z]).*$/i
    //     return reg.test(value); //如果校验是true,就返回true,是false,就返回fasle
    // })
    // $.validator.addMethod("isCheckeUpwd", (value, element, param) => {
    //     var reg = /^\w{6,12}$/i
    //     return reg.test(value); //如果校验是true,就返回true,是false,就返回fasle
    // })
    $("form").validate({
        //规则
        rules: {
            uname: {
                required: true, //true 开启必填项
                //rangelength: [6, 20],
                //isCheckeUname: true, //使用自定义的规则
                //remote: "http://127.0.0.1:8080/checkUname"
            },
            upwd: {
                required: true, //true 开启必填项
                // rangelength: [6, 12],
                // isCheckeUpwd: true,
            }
        },
        
        //消息提示
        messages: {
            uname: {
                required: "用户名必填",
            },
            upwd: {
                required: "密码不能为空",
            }
        },
        submitHandler: function () {

            //调用返回值，返回值结果为true或者false
            var IsBy = $.idcode.validateCode();
            if (IsBy == true) {
                console.log(123789789);
                $.ajax({
                    url: "http://127.0.0.1:8080/api/login",
                    type: "post",
                    data: $("form").serialize(),
                }).then((result) => {
                    if (result.status == 1) {
                        console.log(result);
                        alert("登录成功");
                        window.location.href=("carList.html");
                    }
                    layer.msg(result.msg);
                })

            }

            return false;
        }
    })
})